<%@page import="java.util.ArrayList"%>
<%@page import="com.wanmait.cookbook.vo.Userinfo"%>
<%@page import="com.wanmait.cookbook.vo.Pager"%>
<%@page import="com.wanmait.cookbook.vo.Cookbook"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%String path = request.getContextPath(); %>
<div class="type-tab">
	<div class="type-head clearfix">
		<%-- <a href="<%=path %>/HotCookbookShowListServlet?action=getHotCookbookShowList" one-link-mark="yes">精选</a> --%>
		<a href="<%=path %>/HotCookbookShowListServlet?action=getOnePageCookbook"
			one-link-mark="yes" class="active">精选食谱</a> 
		<a href="<%=path %>/indexServlet?action=getAllRecipeType"
			one-link-mark="yes">食谱分类</a> 
		<a href="<%=path %>/indexServlet?action=getAllIngredientType"
			one-link-mark="yes">食材分类</a>
		<a href="<%=path%>/HotWorksServlet?action=allOnePagerWorksInc"
			one-link-mark="yes">精选作品</a>	
		<hr width="1000">
	</div>
</div>
<h2 class="title">精选推荐菜谱</h2>
<ul id="jxlist" class="clearfix">
	<%
				Userinfo userinfo=(Userinfo)session.getAttribute("userinfo");
				List<Cookbook> allHotCookbook= (List<Cookbook>)request.getAttribute("getPagerCookbook");
				List<Integer> cookbookCount=(List<Integer>)request.getAttribute("cookbookCount");
				List<Boolean> isCollects=new ArrayList<>();
				if(userinfo!=null){
					isCollects=(List<Boolean>)request.getAttribute("isCollects");
				}
				for(int i=0;i<allHotCookbook.size();i++){
					if((i+1)%3!=0){
			%>
	<!-- 循环开始 -->
	<li class="item"><a class="cover" href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=allHotCookbook.get(i).getId() %>" target="_blank"
		style="position: relative" one-link-mark="yes"> <img
			src="<%=path %>/static/image/<%=allHotCookbook.get(i).getPic()%>">
	</a>
		<div class="relative">
			<a class="cookname text-lips" href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=allHotCookbook.get(i).getId() %>" target="_blank"
				one-link-mark="yes"> <%=allHotCookbook.get(i).getTitle() %>
			</a> <a class="author text-lips"
				style="max-width: 170px; vertical-align: middle;"
				href="<%=path %>/PersonalServlet?action=init&id=<%=allHotCookbook.get(i).getUserinfo().getId() %>" target="_blank"
				one-link-mark="yes"> <img
				src="<%=path %>/static/image/<%=allHotCookbook.get(i).getUserinfo().getAvatar()%>">
				<%=allHotCookbook.get(i).getUserinfo().getName() %>
			</a>

			<div class="view-coll">
				<%-- <span class="view">粉丝<%=cookbookCount.get(i) %></span> --%>
				<!-- 收藏开始 -->
					
							<% if(userinfo!=null){
								boolean is=isCollects.get(i);
								if(is){
									%>
									<span  class="shoucangzi">已收藏</span> 
									<img width="15" data-id="<%=allHotCookbook.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangshixin.jpg"><%
								}
								else{
									%>
									<span  class="shoucangzi">收藏</span> 
									<img width="15" data-id="<%=allHotCookbook.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangkongxin.jpg"><%
								}
							}else{
								%>
								<span  class="shoucangzi">收藏</span> 
								<img width="15" data-id="<%=allHotCookbook.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangkongxin.jpg"><% 
							}%>
				<!-- 收藏结束 -->
							
			</div>
		</div></li>
	<%}
					else{
					%>
	<li class="item" style="margin-right: 0px"><a class="cover"
		href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=allHotCookbook.get(i).getId() %>" target="_blank" style="position: relative"
		one-link-mark="yes"> <img
			src="<%=path %>/static/image/<%=allHotCookbook.get(i).getPic()%>">
	</a>
		<div class="relative">
			<a class="cookname text-lips" href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=allHotCookbook.get(i).getId() %>"target="_blank"
				one-link-mark="yes"> <%=allHotCookbook.get(i).getTitle() %>
			</a> <a class="author text-lips"
				style="max-width: 170px; vertical-align: middle;"
				href="<%=path %>/PersonalServlet?action=init&id=<%=allHotCookbook.get(i).getUserinfo().getId() %>" target="_blank"
				one-link-mark="yes"> <img
				src="<%=path %>/static/image/<%=allHotCookbook.get(i).getUserinfo().getAvatar()%>">
				<%=allHotCookbook.get(i).getUserinfo().getName() %>
			</a>

			<div class="view-coll">
				<%-- <span class="view">粉丝<%=cookbookCount.get(i) %></span> --%>
				<!-- 收藏开始 -->
			
							<% if(userinfo!=null){
								boolean is=isCollects.get(i);
								if(is){
									%>
									<span  class="shoucangzi">已收藏</span>
									<img width="15" data-id="<%=allHotCookbook.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangshixin.jpg"><%
								}
								else{
									%>
									<span  class="shoucangzi">收藏</span>
									<img width="15" data-id="<%=allHotCookbook.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangkongxin.jpg"><%
								}
							}else{
								%>
								<span  class="shoucangzi">收藏</span>
								<img width="15"  data-id="<%=allHotCookbook.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangkongxin.jpg"><% 
							}%>
				<!-- 收藏结束 -->
							
							
							
			</div>
		</div></li>
	<%
					}
				} 
				%>
	<!-- 循环结束 -->

	<!--显示小数字结束  -->
</ul>
<!-- 显示数字开始 -->
<div id="cookbookPager" class="pages">
	<%
						Pager pager =(Pager)request.getAttribute("pager");
						int start=1;
						int end=pager.getPageCount();
						if(pager.getPageCount()>5){
							start=pager.getPageNo()-2<1?1:pager.getPageNo()-2;
							end=start+4;
							if(end>pager.getPageCount()){
								end=pager.getPageCount();
								start=end-4;
							}
						}
						%>
						
						<a href="javascript:void(0)" class="prevPager" one-link-mark="yes">上一页</a>
						<% 
						for(int i=start;i<=end;i++){
						if(i==pager.getPageNo()){
							%><a href="javascript:void(0)" style="color:red" class="aliaon" one-link-mark="yes"><%=i %></a>
					<% 	}else{
						%>
						<a href="javascript:void(0)" class="aliaon" one-link-mark="yes"><%=i %></a>
						<% 
							}
						}
							%>
	<a href="javascript:void(0)" class="nextPager" one-link-mark="yes">下一页</a>
	<a href="javascript:void(0)" class="aliaon" one-link-mark="yes"><%=pager.getPageNo() %>/<%=pager.getPageCount() %></a>
<!-- 上下页事件开始 -->
<script type="text/javascript">
$(function(){
	//上一页点击事件
	$(".prevPager").click(function(){
		var n=<%=pager.getPageNo()%>;
		$.ajax({
			url:"<%=path%>/HotCookbookShowListServlet",
			data:{action:"getPagerCookbook",pageNo:n-1},
			success:function(mes){
				$("#content").html(mes);
			}
			
		});
	});
	//下一页点击事件
	$(".nextPager").click(function(){
		var n=<%=pager.getPageNo()%>;
		$.ajax({
			url:"<%=path%>/HotCookbookShowListServlet",
			data:{action:"getPagerCookbook",pageNo:n+1},
			success:function(mes){
				$("#content").html(mes);
			}
			
		});
	});

})
</script>	
<!-- 上下页事件结束 -->
</div>

<p class="fcc">
	你当前的位置：<a href="<%=path %>" title="豆果美食" one-link-mark="yes">豆果美食</a>
	&gt; <a href="<%=path %>/indexServlet?action=getAllRecipeType"
		title="食谱" one-link-mark="yes">食谱</a> &gt; 精选食谱
</p>

<!-- 收藏事件开始 -->
<script type="text/javascript">
	$(function(){
		$(".shoucang").click(function(){
			var cookbookId=$(this).data("id");
			var zi=$(this);
			var shoucangsrc=$(this).attr("src");
			if(<%=userinfo==null%>){
				location.href="<%=path%>/login.jsp";
			}else{
					if(shoucangsrc=="<%=path%>/img/shoucangkongxin.jpg"){
						$(this).attr("src","<%=path%>/img/shoucangshixin.jpg");
						$.ajax({
							url:"<%=path%>/CookbookCollectServlet", 
							data:{action:"addCollection",cookbookId:cookbookId},
							success:function(){
								zi.prev().html("已收藏")
							}
						}) 
						
						
					}
					else{
						$(this).attr("src","<%=path%>/img/shoucangkongxin.jpg");
						$.ajax({
							url:"<%=path%>/CookbookCollectServlet", 
							data:{action:"cancelCollection",cookbookId:cookbookId},
							success:function(){
								zi.prev().html("收藏")
							}
						})
						
						}
			}
			});
	});
</script>
<!-- 收藏事件结束 -->
